package com.crm.jpaandthymeleaf.web.exception;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 周敬
 * @version 1.0
 * @packageName com.crm.jpaandthymeleaf.web.exception
 * @fileName GlobalExceptionHandler
 * @createTime 2021/12/27-17:22-星期一
 * @lastModify 2021/12/27-17:22-星期一
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 当出现 【UnauthorizedException】异常后进入此方法
     * @param request
     * @param e
     * @return
     */
    @ExceptionHandler(UnauthorizedException.class)
    public ModelAndView unauthorizedExceptionHandler(HttpServletRequest request, UnauthorizedException e){
        //设置跳转路径
        ModelAndView mv = new ModelAndView("403");
        //将异常对象传递出去
        mv.addObject("exception",e);
        //获得请求的路径
        mv.addObject("url",request.getRequestURI());
        return mv;
    }
}
